USE [SONALIKA_BGK_UPDATED]
GO

/****** Object:  StoredProcedure [dbo].[SpSpareSalesReport]    Script Date: 05/25/2014 16:41:55 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SpSpareSalesReport]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[SpSpareSalesReport]
GO

USE [SONALIKA_BGK_UPDATED]
GO

/****** Object:  StoredProcedure [dbo].[SpSpareSalesReport]    Script Date: 05/25/2014 16:41:55 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROC [dbo].[SpSpareSalesReport] --2
(@FROM_DATE DATETIME,
@TO_DATE DATETIME)
AS
BEGIN
SELECT DISTINCT SI.SALES_INVOICE_ID
	    ,replace(convert(NVARCHAR, INVOICE_DATE, 106), ' ', '-')AS INVOICE_DATE  
       ,INVOICE_GRANDTOTAL
       ,CUSTOMER_NAME
       
 FROM SPARE_PURCHASES_SALES SPS
     LEFT OUTER JOIN SALES_INVOICES SI ON SI.SALES_INVOICE_ID=SPS.SALES_INVOICE_ID  
     LEFT OUTER JOIN CUSTOMER C ON C.CUSTOMER_ID=SI.CUSTOMER_ID
 
     
 WHERE SELL_TYPE IN (SELECT MASTER_ID FROM MASTER WHERE MASTER_VALUE='SPARE' OR  MASTER_VALUE='LUBRICANT')
 AND (INVOICE_DATE BETWEEN @FROM_DATE AND @TO_DATE)

END





GO


